<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <canvas id="cavsElem" width="400" height="300">

    </canvas>
    <script>
        //获得画布对象
        var canvas = document.getElementById('cavsElem');
        //准备画笔 获得上下文
        var context = canvas.getContext('2d');
        context.linewidth = '3';
        context.strokeStyle = '#f00';
        context.lineCap = 'round';
        //定义起点
        context.moveTo(10, 120);
        //设置端点
        context.lineTo(50, 120);
        context.lineTo(10, 150)
        context.lineTo(50, 150)
            //描边
        context.stroke();
    </script>
</body>

</html>